package com.hehui.partimejob.fragment.category_child;

import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;

import com.hehui.partimejob.R;
import com.hehui.partimejob.fragment.BaseFragment;
import com.hehui.partimejob.js.BaseJSInterface;
import com.hehui.partimejob.js.ShareToCoinJSFace;
import com.hehui.partimejob.view.BaseWebView;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

public class ShareToCoinFragment extends BaseFragment {
    private WebView wv;

    private SmartRefreshLayout refreshLayout;
    private ClassicsHeader header;
    private ClassicsFooter footer;






    @Override
    public void init() {
        getNav().hide();

        refreshLayout = (SmartRefreshLayout) findViewById(R.id.refreshLayout);
        header = (ClassicsHeader) findViewById(R.id.header);
        wv = (WebView) findViewById(R.id.wv);
        footer = (ClassicsFooter) findViewById(R.id.footer);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_share_to_coin;
    }

    @Override
    protected void begin(Bundle bundle) {
        BaseWebView baseWebView = new BaseWebView(wv);
        baseWebView.loadFromAsset("shareToCoin.html");
        Log.d(TAG, "begin: " + baseWebView.getUrl());
        baseWebView.setListener(new BaseWebView.OnBaseWebViewListener() {
            @Override
            public void onPageFinished(BaseWebView webView) {
                //在这里执行你想调用的js函数
                webView.executeJsFunction("a", new BaseWebView.CallBackFromJS<aa>() {
                    @Override
                    public void valueCallback(aa value) {
                        Log.d(TAG, "ValueCallback: " + value.a);
                    }
                });


            }
        });

        //        定义方法给js调用
        ShareToCoinJSFace shareToCoinJSFace = new ShareToCoinJSFace(A);
        shareToCoinJSFace.runInUIThread(new BaseJSInterface.OnJSInterfaceListener() {
            @Override
            public void doSomething() {

            }
        });
        baseWebView.addJavascriptInterface(shareToCoinJSFace);
    }

    public static class aa {
        int a;
        int b;
    }
}
